home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d1 / freemacs.arc / MINT.ASM < prev    next >
Assembly Source File  |  1988-03-17  |  9KB  |  539 lines

  1. ;History:513,2
  2.     .xlist
  3.     include    mintdefs.asm
  4.  
  5. bios_seg    segment at 40h
  6. bios_conin    label    far
  7. bios_status    label    far
  8. bios_seg    ends
  9.  
  10.  
  11. BS    equ    08h
  12. LF    equ    0ah
  13. CR    equ    0dh
  14. ESC    equ    1bh
  15. DEL    equ    07fh
  16.  
  17. data    segment    public
  18.  
  19. ;the _mark constants mark where a particular type of string occurs in
  20. ; the linked list.
  21.  
  22. comma_marker    equ    0    ;comma_marker must not have function_marker_mask set!
  23. active_marker    equ    1    ;active_marker must have function_marker_mask set!
  24. neutral_marker    equ    3    ;neutral_marker must have function_marker_mask set!
  25. function_marker_mask    equ    1
  26.  
  27.     extrn    trace:    byte
  28.     extrn    formb:    word
  29.     extrn    forme:    word
  30.     extrn    fbgn:    word
  31.     extrn    fend:    word
  32.     extrn    actptr:    word
  33. metachar    db    "'"    ;metachar is initially '
  34.  
  35.     extrn    next_ids: word
  36.  
  37.     public    ids
  38. ids        db    "#(ps,(",CR,LF,"))#(ps,#(rs))",0
  39. ids_user    db    "#(ps,#(bk))",0
  40.  
  41. breakchar    db    3        ;use ^C.
  42.  
  43. data    ends
  44.  
  45.  
  46. code    segment    public
  47.     assume    cs:code, ds:data, es:data
  48.  
  49.     public    mint_init
  50. mint_init:
  51.     ret
  52.  
  53.     extrn    init_ids: near
  54.     extrn    nomem: near
  55.  
  56. ;this routine should check for a break character.  If it gets one, it
  57. ;  gets rid of its return address and jump to init_ids.  The check should
  58. ;  be a non-destructive test, i.e. it should not suck up any characters
  59. ;  except the chosen break character.  Also, no registers should be changed.
  60.     public    check_breakchar
  61. check_breakchar:
  62.     push    ax
  63.     call    bios_status
  64.     jz    check_breakchar_1
  65.     cmp    al,breakchar
  66.     jne    check_breakchar_1
  67.     call    bios_conin        ;get rid of the break character.
  68.     add    sp,4            ;get rid of the return address.
  69.     jmp    init_ids
  70. check_breakchar_1:
  71.     pop    ax
  72.     ret
  73.  
  74.  
  75. da_prim:
  76. da_prim_1:
  77.     mov    bx,formb    ;any forms left?
  78.     cmp    bx,forme
  79.     je    da_prim_2    ;no, exit.
  80.     call    delete_form    ;yes, delete one of them and continue.
  81.     jmp    da_prim_1
  82. da_prim_2:
  83.     jmp    return_null
  84.  
  85.  
  86. cs_prim:
  87.     call    find_arg1
  88.     jnc    cs_prim_1    ;if not found, return null.
  89.     jcxz    cs_prim_2    ;if form pointer at end, return arg 2.
  90.     di_points_fbgn
  91. cs_prim_3:
  92.     lodsb
  93.     cmp    al,sgap
  94.     ja    cs_prim_4    ;terminate on sgap1..127's.
  95.     je    cs_prim_5    ;ignore sgap0's
  96.     chk_actptr
  97.     stosb
  98. cs_prim_5:
  99.     loop    cs_prim_3
  100.     jmp    return_form    ;we ran off the end.
  101. cs_prim_4:
  102.     dec    cx        ;move past the sgap.
  103.     jmp    return_form
  104. cs_prim_2:
  105.     mov    cx,2
  106.     jmp    return_arg_active
  107. cs_prim_1:
  108.     jmp    return_null
  109.  
  110.  
  111. cc_prim:
  112.     call    find_arg1
  113.     jnc    cc_prim_1    ;form not found.
  114.     jcxz    cc_prim_2    ;no chars left.
  115.     lodsb            ;get the character.
  116.     push    ax
  117. cc_prim_3:
  118.     lodsb            ;get the next character
  119.     test    al,sgap
  120.     loopne    cc_prim_3    ;keep looking while we still have sgaps.
  121.     jne    cc_prim_4    ;if the last character is a real character,
  122.     dec    si        ;  make the form pointer point to it.
  123.     inc    cx
  124. cc_prim_4:
  125.     pop    ax        ;restore the character
  126.     di_points_fbgn
  127.     stosb            ;no need to check for collision with actptr.
  128.     dec    cx
  129.     jmp    return_form
  130. cc_prim_2:
  131.     mov    cx,2
  132.     jmp    return_arg_active
  133. cc_prim_1:
  134.     jmp    return_null
  135.  
  136.  
  137. cn_prim:
  138.     call    find_arg1
  139.     jnc    cn_prim_1
  140.     jcxz    cn_prim_2
  141.     push    si        ;save pointer, count to form.
  142.     push    cx
  143.     push    bx
  144.     mov    cx,2        ;get number of chars to call.
  145.     call    getarg
  146.     call    get_decimal
  147.     mov    dx,ax        ;save in dx.
  148.     pop    bx
  149.     pop    cx
  150.     pop    si
  151.     di_points_fbgn
  152. cn_prim_3:
  153.     or    dx,dx        ;have we called the specified number of chars?
  154.     jz    cn_prim_4
  155.     lodsb
  156.     or    al,al        ;don't move sgaps.
  157.     jl    cn_prim_5
  158.     chk_actptr        ;store the char.
  159.     stosb
  160.     dec    dx        ;decrement the count.
  161. cn_prim_5:
  162.     loop    cn_prim_3    ;keep going until we run out of chars.
  163.     jmp    short cn_prim_6
  164. ;scan forwards until the next character is found.
  165. cn_prim_4:
  166.     lodsb            ;get the next character
  167.     test    al,sgap
  168.     loopne    cn_prim_4    ;keep looking while we still have sgaps.
  169.     jne    cn_prim_6    ;if the last character is a real character,
  170.     dec    si        ;  make the form pointer point to it.
  171.     inc    cx
  172. cn_prim_6:
  173.     jmp    return_form
  174. cn_prim_2:
  175.     mov    cx,3
  176.     jmp    return_arg_active
  177. cn_prim_1:
  178.     jmp    return_null
  179.  
  180.  
  181.  
  182. pf_prim:
  183.     call    find_arg1
  184.     jnc    pf_prim_1
  185.     mov    cx,[bx].data_length
  186.     lea    si,[size form + bx]
  187.     add    si,[bx].name_length
  188.     mov    dx,0
  189. pf_prim_2:
  190.     cmp    dx,[bx].form_pointer
  191.     jne    pf_prim_3
  192.     call    reverse_video
  193.     mov    al,"^"
  194.     call    printchar
  195.     call    normal_video
  196. pf_prim_3:
  197.     jcxz    pf_prim_1
  198.     lodsb
  199.     cmp    al,sgap
  200.     je    pf_prim_5    ;ignore sgap0s.
  201.     jb    pf_prim_4    ;print characters.
  202.     push    ax
  203.     call    reverse_video
  204.     pop    ax
  205.     sub    ax,sgap-"0"
  206.     call    printchar
  207.     call    normal_video
  208.     jmp    pf_prim_5
  209. pf_prim_4:
  210.     call    printchar
  211. pf_prim_5:
  212.     inc    dx
  213.     dec    cx
  214.     jmp    pf_prim_2
  215. pf_prim_1:
  216.     jmp    return_null
  217.  
  218.  
  219. rs_prim:
  220.     di_points_fbgn
  221.     mov    cx,0
  222. rs_prim_1:
  223.     call    readchar    ;reads without echo
  224.     cmp    al,DEL        ;delete?
  225.     je    rs_prim_4
  226.     cmp    al,BS        ;backspace? if so, delete char.
  227.     jne    rs_prim_2
  228. rs_prim_4:
  229.     jcxz    rs_prim_1    ;if no chars, ignore it.
  230.     cmp    byte ptr [di-1],LF    ;don't delete past lf.
  231.     je    rs_prim_1
  232.     dec    cx        ;dec count
  233.     dec    di        ;dec pointer
  234.     mov    al,BS        ;erase char from screen.
  235.     call    printchar
  236.     mov    al," "
  237.     call    printchar
  238.     mov    al,BS
  239.     call    printchar
  240.     jmp    rs_prim_1
  241. rs_prim_2:
  242.     cmp    al,metachar    ;end of input?
  243.     jne    rs_prim_3
  244.     jmp    return_tos
  245. rs_prim_3:
  246.     cmp    al,CR
  247.     jne    rs_prim_6
  248.     call    rs_prim_store
  249.     mov    al,LF
  250.     call    rs_prim_store
  251.     jmp    rs_prim_1
  252. rs_prim_6:
  253.     cmp    al,breakchar    ;break character?
  254.     jne    rs_prim_5
  255.     jmp    init_ids
  256. rs_prim_5:
  257.     call    rs_prim_store
  258.     jmp    rs_prim_1
  259. rs_prim_store:
  260.     stosb            ;store the char
  261.     call    printchar    ;print the char
  262.     chk_actptr
  263.     inc    cx        ;bump the count
  264.     ret
  265.  
  266.  
  267. cm_prim:
  268.     call    getarg1
  269.     mov    al,"'"
  270.     jcxz    cm_prim_1
  271.     lodsb
  272. cm_prim_1:
  273.     mov    metachar,al
  274.     jmp    return_null
  275.  
  276.  
  277. um_prim:
  278.     mov    next_ids,offset ids_user
  279.     jmp    return_null
  280.  
  281.  
  282. tn_prim:
  283.     call    getarg1
  284.     mov    trace,1
  285.     jcxz    tn_prim_1    ;if arg not empty,
  286.     mov    trace,2        ;  do trace with pause.
  287. tn_prim_1:
  288.     jmp    return_null
  289.  
  290.  
  291. tf_prim:
  292.     mov    trace,0
  293.     jmp    return_null
  294.  
  295.  
  296.     public    reverse_video
  297. reverse_video:
  298.     mov    al,ESC
  299.     call    printchar
  300.     mov    al,"p"
  301.     call    printchar
  302.     ret
  303.  
  304.  
  305.     public    normal_video
  306. normal_video:
  307.     mov    al,ESC
  308.     call    printchar
  309.     mov    al,"q"
  310.     call    printchar
  311.     ret
  312.  
  313.  
  314.     public    trace_result
  315. trace_result:
  316. ;enter with si->, cx=count of returning result of a primitive call.
  317. ;doesn't modify si or cx.
  318.     cmp    trace,0
  319.     je    trace_result_3
  320.     push    si
  321.     push    cx
  322.     call    reverse_video
  323.     jcxz    trace_result_1
  324. trace_result_2:
  325.     lodsb
  326.     call    printchar
  327.     loop    trace_result_2
  328. trace_result_1:
  329.     call    normal_video
  330.     cmp    trace,2        ;if pause,
  331.     jne    trace_result_4
  332.     call    readchar    ;then wait for a character.
  333. trace_result_4:
  334.     call    printcrlf
  335.     pop    cx
  336.     pop    si
  337. trace_result_3:
  338.     ret
  339.  
  340.  
  341.     public    trace_invoke
  342. trace_invoke:
  343. ;enter with bx->fbgn, al=function type (active or neutral)
  344.     cmp    trace,0
  345.     je    trace_invoke_6
  346.     push    bx
  347.     cmp    al,neutral_marker
  348.     jne    trace_invoke_1
  349.     mov    al,"#"
  350.     call    printchar
  351. trace_invoke_1:
  352.     mov    al,"#"
  353.     call    printchar
  354.     mov    al,"("
  355.     call    printchar
  356. trace_invoke_3:
  357.     mov    si,bx
  358.     mov    bx,[bx]
  359.     cmp    si,bx        ;at end?
  360.     je    trace_invoke_2    ;yes.
  361.     mov    cx,bx
  362.     sub    cx,si
  363.     sub    cx,mark_overhead    ;remove overhead.
  364.     add    si,mark_overhead-1        ;skip past overhead.
  365.     jcxz    trace_invoke_5
  366. trace_invoke_4:
  367.     lodsb
  368.     call    printchar
  369.     loop    trace_invoke_4
  370. trace_invoke_5:
  371.     cmp    bx,[bx]            ;last argument?
  372.     je    trace_invoke_3        ;yes - don't print comma.
  373.     mov    al,","
  374.     call    printchar
  375.     jmp    trace_invoke_3
  376. trace_invoke_2:
  377.     mov    al,")"
  378.     call    printchar
  379.     pop    bx
  380. trace_invoke_6:
  381.     ret
  382.  
  383.  
  384.     public    rc_prim
  385. rc_prim:
  386.     call    readchar
  387.     cmp    al,breakchar
  388.     je    rc_prim_1
  389.     di_points_fbgn
  390.     stosb
  391.     jmp    return_tos
  392. rc_prim_1:
  393.     jmp    init_ids
  394.  
  395.  
  396. ps_prim:
  397.     call    getarg1
  398.     jcxz    ps_prim_2
  399. ps_prim_1:
  400.     lodsb
  401.     call    printchar
  402.     loop    ps_prim_1
  403. ps_prim_2:
  404.     jmp    return_null
  405.  
  406.  
  407.     extrn    getarg1: near
  408.     extrn    return_form: near
  409.     extrn    return_arg_active: near
  410.     extrn    getarg: near
  411.     extrn    get_decimal: near
  412.     extrn    return_null: near
  413.     extrn    return_tos: near
  414.     extrn    printchar: near
  415.     extrn    printcrlf: near
  416.     extrn    readchar: near
  417.     extrn    find_arg1: near
  418.     extrn    delete_form: near
  419.  
  420. code    ends
  421.  
  422. data    segment public
  423.  
  424.     public    function_name_table
  425.     public    function_name_length
  426.     public    function_address
  427.  
  428. function_name_table    label    word
  429.     db    "ps"
  430.     db    "rs"
  431.     db    "cm"
  432.     db    "hl"
  433.     db    "eq"
  434.     db    "um"
  435.     db    "rc"
  436.     db    "tn"
  437.     db    "tf"
  438.     db    "nc"
  439.     db    "sc"
  440.     db    "db"
  441.     db    "dt"
  442.     db    "tm"
  443. ;forms
  444.     db    "ds"
  445.     db    "ss"
  446.     db    "pf"
  447.     db    "cl"
  448.     db    "cs"
  449.     db    "cc"
  450.     db    "cn"
  451.     db    "cr"
  452.     db    "in"
  453.     db    "ln"
  454.     db    "dd"
  455.     db    "da"
  456.     db    "sb"
  457.     db    "fb"
  458.     db    "nb"
  459. ;math
  460.     db    "ad"
  461.     db    "su"
  462.     db    "ml"
  463.     db    "dv"
  464.     db    "gr"
  465.  
  466. function_name_length    equ ($-function_name_table)/2
  467.  
  468.     dw    dflt
  469. function_address    label    word
  470.     dw    ps_prim
  471.     dw    rs_prim
  472.     dw    cm_prim
  473.     dw    hl_prim
  474.     dw    eq_prim
  475.     dw    um_prim
  476.     dw    rc_prim
  477.     dw    tn_prim
  478.     dw    tf_prim
  479.     dw    nc_prim
  480.     dw    sc_prim
  481.     dw    db_prim
  482.     dw    dt_prim
  483.     dw    tm_prim
  484. ;forms
  485.     dw    ds_prim
  486.     dw    ss_prim
  487.     dw    pf_prim
  488.     dw    cl_prim
  489.     dw    cs_prim
  490.     dw    cc_prim
  491.     dw    cn_prim
  492.     dw    cr_prim
  493.     dw    in_prim
  494.     dw    ln_prim
  495.     dw    dd_prim
  496.     dw    da_prim
  497.     dw    sb_prim
  498.     dw    fb_prim
  499.     dw    nb_prim
  500. ;math
  501.     dw    ad_prim
  502.     dw    su_prim
  503.     dw    ml_prim
  504.     dw    dv_prim
  505.     dw    gr_prim
  506.  
  507. data    ends
  508.  
  509. code    segment    public
  510.     extrn    dflt: near
  511.     extrn    hl_prim: near
  512.     extrn    eq_prim: near
  513.      extrn    nc_prim: near
  514.     extrn    sc_prim: near
  515.     extrn    db_prim: near
  516.     extrn    dt_prim: near
  517.     extrn    tm_prim: near
  518. ;forms
  519.     extrn    ds_prim: near
  520.     extrn    ss_prim: near
  521.     extrn    cl_prim: near
  522.     extrn    cr_prim: near
  523.     extrn    in_prim: near
  524.     extrn    ln_prim: near
  525.     extrn    dd_prim: near
  526.     extrn    sb_prim: near
  527.     extrn    fb_prim: near
  528.     extrn    nb_prim: near
  529. ;math
  530.     extrn    ad_prim: near
  531.     extrn    su_prim: near
  532.     extrn    ml_prim: near
  533.     extrn    dv_prim: near
  534.     extrn    gr_prim: near
  535.  
  536. code    ends
  537.  
  538.     end
  539.